<?php


class Api_chongzhi_mdl extends CI_Model
{
	const TBL_USERS = 'cj_users';
	
	public function __construct()
	{
		parent::__construct();
	}
	
	public function outputdata($data)
	{	
		
		header('Content-Type:text/html; charset=utf-8', false);
		$this->db->select('*')->from(self::TBL_USERS)->where('uid', $data['USERID'])->limit(1);
		$query = $this->db->get();
		if($query->num_rows() == 1)
		{
			$userdata = $query->row_array();
		}
		
		$user['txgoldnum'] = intval($userdata['txgoldnum']);
		$tmp['txgoldnum'] = $userdata['txgoldnum']+1000;

		$this->db->where('uid', intval($data['USERID']));
		$this->db->update(self::TBL_USERS, $tmp);
	
		$outputdata['TAG'] = $data['TAG'];
		$outputdata['GOLD'] = $user['txgoldnum']+1000;
		$outputdata['STATUS'] = 0;
		$outputdata['ERRORMESSAGE'] = null;

		echo json_encode($outputdata);
		
	}
	
	/**
	 * 
	 * 活动奖品...
	 * @param int $id
	 */
	private function getproducts($id)
	{
		$flag = $this->db->select('product.productname,product.id,product.ptype,product.content,lottery.rnum,lottery.rewardid')
				->where('lottery.rewardid',$id)
				->join('cj_products as product','lottery.productid = product.id')
				->from('cj_lottery as lottery')
				->get()->result_array();
		$result = array();
		if(!empty($flag))
		{
			foreach($flag as $v)
			{
				$tmp['id'] = (int)$v['id'];
				$tmp['productName'] = $v['productname'];
				$tmp['ptype'] = (int)$v['ptype'];
				$tmp['content'] = $v['content'];
				$result[] = $tmp;
			}
		}
		return $result;
	}
	
}